home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / frntsdk1.cpt / Frontier SDK 1.0 ƒ / Applet Toolkit / font.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-21  |  3.2 KB  |  184 lines

  1.  
  2. /*⌐ Copyright 1988-1991 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletinternal.h"
  6. #include "ops.h"
  7. #include "font.h"
  8.  
  9.  
  10. #define styleseparator "\p+"
  11.  
  12. FontInfo globalfontinfo;
  13.  
  14.  
  15.  
  16. void setfontsizestyle (short fontnum, short fontsize, short fontstyle) {
  17.  
  18.     TextFont (fontnum);
  19.     
  20.     TextSize (fontsize);
  21.     
  22.     TextFace (fontstyle);
  23.     } /*setfontsizestyle*/
  24.     
  25.     
  26. void setglobalfontsizestyle (short fontnum, short fontsize, short fontstyle) {
  27.  
  28.     setfontsizestyle (fontnum, fontsize, fontstyle);
  29.     
  30.     GetFontInfo (&globalfontinfo);
  31.     } /*setglobalfontsizestyle*/
  32.     
  33.     
  34. short setnamedfont (bigstring bs, short fsize, short fstyle, short defaultfont) {
  35.  
  36.     /*
  37.     give me the name of a font you like.  I'll try to set to that font,
  38.     but if its not available, you get the default font.  be sure to select
  39.     a default font that is mandatory -- like geneva or newYork.
  40.     */
  41.     
  42.     short fontnum;
  43.     
  44.     GetFNum (bs, &fontnum);
  45.     
  46.     if (fontnum == 0) 
  47.         fontnum = defaultfont; /*use caller's second choice*/
  48.         
  49.     setglobalfontsizestyle (fontnum, fsize, fstyle);
  50.     
  51.     return (fontnum); /*return the font that we are actually using*/
  52.     } /*setnamedfont*/
  53.         
  54.  
  55. void getfontsizestyle (short *fontnum, short *fontsize, short *fontstyle) {
  56.  
  57.     *fontnum = (*quickdrawglobal (thePort)).txFont;
  58.     
  59.     *fontsize = (*quickdrawglobal (thePort)).txSize;
  60.     
  61.     *fontstyle = (*quickdrawglobal (thePort)).txFace;
  62.     } /*getfontsizestyle*/
  63.     
  64.     
  65. void fontstring (short fontnum, short fontsize, boolean flhavefont, boolean flhavesize, bigstring bs) {
  66.  
  67.     bigstring bsint;
  68.     
  69.     bs [0] = (char) 0; /*set it to the empty string*/
  70.     
  71.     if (flhavefont)
  72.         GetFontName (fontnum, bs);
  73.         
  74.     if (flhavesize) {    
  75.     
  76.         NumToString (fontsize, bsint);
  77.         
  78.         if (flhavefont) {
  79.             
  80.             pushspace (bs);
  81.             
  82.             pushstring (bsint, bs);    
  83.             }        
  84.         else
  85.             copystring ("\pno consistent font", bs);
  86.         }
  87.     } /*fontstring*/
  88.     
  89.  
  90. void getstyle (short style, short *flplain, short *flbold, short *flitalic, short *flunderline, short *floutline, short *flshadow) {
  91.  
  92.     /*
  93.     give me a style bit array, and I'll extract the booleans which are 
  94.     slightly easier to deal with.
  95.     
  96.     if none of the others are true, we set flplain to true.  otherwise 
  97.     flplain is false.
  98.     */
  99.  
  100.     *flplain = true;  /*default values*/
  101.     
  102.     *flbold = false;
  103.     
  104.     *flitalic = false;
  105.     
  106.     *flunderline = false;
  107.     
  108.     *floutline = false;
  109.     
  110.     *flshadow = false;
  111.     
  112.     if (style >= shadow) {
  113.         
  114.         style -= shadow;
  115.         
  116.         *flshadow = true;
  117.         
  118.         *flplain = false;
  119.         }
  120.         
  121.     if (style >= outline) {
  122.         
  123.         style -= outline;
  124.         
  125.         *floutline = true;
  126.         
  127.         *flplain = false;
  128.         }
  129.         
  130.     if (style >= underline) {
  131.         
  132.         style -= underline;
  133.         
  134.         *flunderline = true;
  135.         
  136.         *flplain = false;
  137.         }
  138.         
  139.     if (style >= italic) {
  140.         
  141.         style -= italic;
  142.         
  143.         *flitalic = true;
  144.         
  145.         *flplain = false;
  146.         }
  147.         
  148.     if (style >= bold) {
  149.         
  150.         style -= bold;
  151.         
  152.         *flbold = true;
  153.         
  154.         *flplain = false;
  155.         }
  156.     } /*getstyle*/
  157.     
  158.  
  159. void checkstyle (boolean fl, bigstring bsin, bigstring bsout) {
  160.  
  161.     if (fl) {
  162.         if (bsout [0]) { /*already something on the output string*/
  163.         
  164.             pushstring (styleseparator, bsout);
  165.             
  166.             pushstring (bsin, bsout);
  167.             }
  168.         else
  169.             copystring (bsin, bsout);
  170.         }
  171.     } /*checkstyle*/
  172.         
  173.  
  174. short getfontheight (void) {
  175.     
  176.     FontInfo info;
  177.     
  178.     GetFontInfo (&info);
  179.     
  180.     return (info.ascent + info.descent);
  181.     } /*getfontheight*/
  182.     
  183.     
  184.